import React from 'react'
import PropTypes from 'prop-types'
import { Switch, Route, Redirect, routerRedux } from 'dva/router'
import dynamic from 'dva/dynamic'
import App from 'routes/app'

const { ConnectedRouter } = routerRedux

const Routers = function ({ history, app }) {
  const error = dynamic({
    app,
    component: () => import('./routes/error'),
  })
  const routes = [
    {
      path: '/chzu/peopleManage',
      // models: () => [import('./models/peopleManage')],
      component: () => import('./routes/peopleManage/'),
    }, {
      path: '/chzu/login',
      models: () => [import('./models/login')],
      component: () => import('./routes/login/'),
    }, {
      path: '/chzu/faqManage',
      models: () => [import('./models/faqManage')],
      component: () => import('./routes/faqManage')
    },{
      path: '/chzu/faqManage/faqDetail',
      models: () => [import('./models/faqManage/faqDetail')],
      component: () => import('./routes/faqManage/faqDetail')
    },
    {
      path: '/chzu/noticeManage',
      models: () => [import('./models/noticeManage/noticeManage')],
      component: () => import('./routes/noticeManage')
    },{
      path: '/bshrecipes/addArticle',
      models: ()=> [import('./models/articleManage/article')],
      component: () => import('./routes/articleManage/addArticle')
    },{
      path: '/bshrecipes/articleList',
      models: ()=> [import('./models/articleManage/articleList')],
      component: () => import('./routes/articleManage')
    },{
      path: '/bshrecipes/articleDetail/:id',
      models: ()=> [import('./models/articleManage/article')],
      component: () => import('./routes/articleManage/articleDetail')
    },{
      path: '/chzu/schoolManage/school',
      models: ()=>[import ('./models/schoolManage')],
      component:()=>import('./routes/schoolManage/school')
    },{
      path:'/chzu/schoolManage/department/:id/:name',
      models: ()=>[import ('./models/schoolManage')],
      component:() => import('./routes/schoolManage/department')
    },{
      path:'/chzu/schoolManage/specialty/:id/:school/:name',
      models:()=>[import('./models/schoolManage')],
      component:() => import('./routes/schoolManage/specialty')
    },
    {
      path:'/chzu/userNotice',
      models:() => [import('./models/noticeManage/noticeManage')],
      component:() => import('./routes/userNotice/index'),
    },{
      path:'/chzu/notreatList',
      models: ()=>[import('./models/repairManage')],
      component: ()=> import('./routes/repairManage/notreatList'),
    },{
      path: '/chzu/ingList',
      models: ()=>[import('./models/repairManage')],
      component:()=> import('./routes/repairManage/ingList'),
    },{
      path:'/chzu/endList',
      models: ()=>[import('./models/repairManage')],
      component:()=>import('./routes/repairManage/endList'),
    },{
      path:'/chzu/notreatList/repairDetail/:id',
      models: ()=>[import('./models/repairManage')],
      component: ()=>import('./routes/repairManage/notreatList/detail')
    },{
      path:'/chzu/ingList/repairDetail/:id',
      models: ()=>[import('./models/repairManage')],
      component: ()=>import('./routes/repairManage/ingList/detail')
    },{
      path:'/chzu/endList/repairDetail/:id',
      models: ()=>[import('./models/repairManage')],
      component: ()=>import('./routes/repairManage/endList/detail')
    },{
      path:'/chzu/userCenter',
      models: ()=>[import('./models/userCenter')],
      component: ()=>import('./routes/User/index')
    }
  ]

  return (
    <ConnectedRouter history={history}>
      <App>
        <Switch>
          <Route exact path="/" render={() => (<Redirect to="/chzu/peopleManage" />)} />
          {
            routes.map(({ path, ...dynamics }, key) => (
              <Route key={key}
                exact
                path={path}
                component={dynamic({
                  app,
                  ...dynamics,
                })}
              />
            ))
          }
          <Route component={error} />
        </Switch>
      </App>
    </ConnectedRouter>
  )
}

Routers.propTypes = {
  history: PropTypes.object,
  app: PropTypes.object,
}

export default Routers
